//-------------------------------------------------------------------
//	Copyright (c) 2010-2012 Zhirnov Andrey
//	This file is part of the "UXGEN" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#ifndef _UX_WINDOW_H
#define _UX_WINDOW_H

#include <Includes.h>
#include "../Render/CRender.h"

namespace Engine
{
namespace CoreSystems
{

	//
	// Window interface
	//

	class IWindow : public CEngBaseObject
	{
	private:
		IThread		*	_pThread;
		TGLWindow	*	_pWindow;
		CRender		*	_pRender;
		
	protected:
		IWindow(IThread *pThread, TGLWindow *pWnd, CRender *pRender);

		virtual void _FreeShared(IWindow *pWnd) = 0;

	public:
		virtual bool Create(const TGLWindow::TDescriptorExt &sDesc, const char *pCaption = nullptr, TWindowClass *pClass = nullptr) = 0;
		virtual bool CreateShared(e_thread::type eType, IWindow *&pWnd) = 0;
		virtual IWindow * ParentWindow() const = 0;
		virtual void Release();

		IThread   *	Thread()	const	{ return _pThread; }
		TGLWindow *	Window()	const	{ return _pWindow; }
		CRender	  *	Render()	const	{ return _pRender; }
	};



	//
	// Main Window
	//

	class CMainWindow : public IWindow
	{
	private:
		typedef array< IWindow *, TFastCopyStrategy< IWindow *> >	window_array_t;

	private:
		window_array_t		_aShared;
		CMainWindowThread	_cThread;
		TGLGameWindow		_cWindow;
		CInput				_cInput;
		TWindowClass		_cWndClass;
		TWindowIcon			_cIcon;
		CRender				_cRender;
		
	protected:
		virtual void _FreeShared(IWindow *pWnd);

	public:
		CMainWindow();
		~CMainWindow();
		
		bool Create(const TGLWindow::TDescriptorExt &sDesc, const char *pCaption, const char *pIcon);
		virtual bool Create(const TGLWindow::TDescriptorExt &sDesc, const char *pCaption, TWindowClass *pClass);
		virtual bool CreateShared(e_thread::type eType, IWindow *&pWnd);
		virtual IWindow * ParentWindow() const;
	};



	//
	// Render Window
	//

	class CRenderWindow : public IWindow
	{
	private:
		Ptr< IWindow >		_pParent;
		CWindowThread		_cThread;
		TGLGameWindow		_cWindow;
		CInput				_cInput;
		CRender				_cRender;
		
	protected:
		virtual void _FreeShared(IWindow *pWnd);

	public:
		CRenderWindow(IWindow *pParent);
		~CRenderWindow();

		virtual bool Create(const TGLWindow::TDescriptorExt &sDesc, const char *pCaption, TWindowClass *pClass);
		virtual bool CreateShared(e_thread::type eType, IWindow *&pWnd);
		virtual IWindow * ParentWindow();
	};



	//
	// Load Window
	//

	class CLoadWindow : public IWindow
	{
	private:
		Ptr< IWindow >		_pParent;
		CWindowThread		_cThread;
		TGLWindow			_cWindow;
		CRender				_cRender;
		
	protected:
		virtual void _FreeShared(IWindow *pWnd);

	public:
		CLoadWindow(IWindow *pParent);
		~CLoadWindow();
		
		virtual bool Create(const TGLWindow::TDescriptorExt &sDesc, const char *pCaption, TWindowClass *pClass);
		virtual bool CreateShared(e_thread::type eType, IWindow *&pWnd);
		virtual IWindow * ParentWindow();
	};

//-------------------------------------------------------------------

}	// CoreSystems
}	// Engine

#endif	// _UX_WINDOW_H